from fastapi import FastAPI
import fastapi_cdn_host
from .settings import setting
from src.apps.home import home_router
from src.apps.system import SystemRouter
from .utils.common_middleware import add_cors_middleware
from .utils.common_db import register_mysql
from .utils.common_exception import register_exception
from .utils.common_logger import get_logger
from fastapi.staticfiles import StaticFiles

def register_router(app: FastAPI):
    app.include_router(home_router, prefix="/api/v1/home", tags=['首页所有的路由'])
    app.include_router(SystemRouter, prefix='/api/v1/system', tags=['系统所有路由'])


def register_middle_ware(app: FastAPI):
    add_cors_middleware(app)


def create_app() -> FastAPI:
    app = FastAPI()
    fastapi_cdn_host.patch_docs(app)

    register_router(app)

    register_middle_ware(app)

    register_mysql(app)

    register_exception(app)

    app.mount("/media", StaticFiles(directory='media'), name='media')

    return app

